package com.itheima.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class Demo1接收端 {
    public static void main(String[] args) throws IOException {
        while (true) {
            MulticastSocket ms = new MulticastSocket(10000);
            byte[] b = new byte[1024];

            DatagramPacket dp = new DatagramPacket(b, 1024);

            ms.joinGroup(InetAddress.getByName("224.0.1.0"));
            ms.receive(dp);

            int length = dp.getLength();
            System.out.println(new String(b, 0, length));
        }
    }
}
